package threadsafe;

/**
 * Created by 5406160@qq.com on LiBoWen 李博闻.
 *
 * @ClassName : SellTicket
 * @Author : 54061
 * @Date: 2022/2/15 17:58
 */
/*

 */
public class SellTicket implements Runnable{
    //总票数 : 共享数据
    int ticket = 100;


    @Override
    public void run() {
        //火车站不关门
        while (true){
            //判断
            if (ticket > 0){
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                //买票
                System.out.println(Thread.currentThread().getName()+"买了第"+ticket+"张票");
                //真正的买票
                ticket--;
            }
        }
    }
}
